package com.ihrm.common.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.domain.Specification;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

/**
 * @auther chongxiongwei
 * @create 2020-04-16-10:01
 */
@Slf4j
public class BaseService<T> {

    protected Specification<T> getSpec(String companyId){
        log.info("*****companyid******"+companyId);

        Specification<T> specification =new Specification<T>() {
            @Override
            public Predicate toPredicate(Root<T> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
                return criteriaBuilder.equal(root.get("companyId").as(String.class),companyId);
            }
        };
        return specification;
    }

}
